package com.ygqh.baby.service.ngmm.api;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.ResourceBundle;

import com.ygqh.baby.service.BaseApi;
import com.ygqh.baby.service.ngmm.http.NgmmRequestExecutor;
import com.ygqh.baby.service.ngmm.util.NgmmConfigure;
import com.ygqh.baby.utils.DateConvertUtils;
import com.ygqh.baby.utils.MD5;
import com.ygqh.baby.utils.MapUtil;

/**
 */
public class MpApi extends BaseApi {

	private final static ResourceBundle NGMM_BUNDLE;

	protected final NgmmRequestExecutor ngmmRequestExecutor;

	static {
		NGMM_BUNDLE = ResourceBundle.getBundle("prop/ngmm");
	}

	public MpApi() {
		super();
		this.ngmmRequestExecutor = new NgmmRequestExecutor();
	}

	public String getSign(Map<String, String> signParam) {
		String joinStr = MapUtil.toJoinStrASCII(signParam, false, false);
		String APP_SECRET = getRequestUri(NgmmConfigure.APP_SECRET);
		String result = MD5.MD5Encode(APP_SECRET.concat(joinStr).concat(APP_SECRET)).toUpperCase();
		return result;
	}

	public Map<String, String> getApplicationParam() {
		Map<String, String> map = new HashMap<String, String>();
		map.put("app_key", getRequestUri(NgmmConfigure.APP_KEY));
		map.put("app_secret", getRequestUri(NgmmConfigure.APP_SECRET));
		map.put("timestamp", DateConvertUtils.formatDateTime(new Date()));
		return map;
	}

	@Override
	protected ResourceBundle bundle() {
		return NGMM_BUNDLE;
	}
}
